# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: inkyu

from recordclass import recordclass

from coin.exchange.bitfinex_v2.fill import FillCollector

_BitfinexOrderInternal = recordclass(
    'BitfinexOrderInternal',
    ['exchange_order_id', 'group_id', 'fill', 'timestamp', 'timestamp_submit', 'maker', 'working'])


class BitfinexOrderInternal(_BitfinexOrderInternal):
  @staticmethod
  def create_by_submit(*, timestamp_submit, price_orig, qty_orig):
    return BitfinexOrderInternal._create(timestamp_submit=timestamp_submit,
                                         price_orig=price_orig,
                                         qty_orig=qty_orig)

  @staticmethod
  def create_by_order_update(*,
                             price_orig,
                             qty_orig,
                             exchange_order_id,
                             group_id,
                             timestamp,
                             working):
    return BitfinexOrderInternal._create(price_orig=price_orig,
                                         qty_orig=qty_orig,
                                         exchange_order_id=exchange_order_id,
                                         group_id=group_id,
                                         timestamp=timestamp,
                                         working=working)

  @staticmethod
  def create_by_trade_event(*,
                            price_orig=None,
                            qty_orig=None,
                            exchange_order_id=None,
                            timestamp=None,
                            maker=None):
    return BitfinexOrderInternal._create(price_orig=price_orig,
                                         qty_orig=qty_orig,
                                         exchange_order_id=exchange_order_id,
                                         timestamp=timestamp,
                                         maker=maker)

  @staticmethod
  def _create(*,
              timestamp_submit=None,
              timestamp=None,
              price_orig=None,
              qty_orig=None,
              exchange_order_id=None,
              group_id=None,
              maker=None,
              working=True):
    return BitfinexOrderInternal(timestamp_submit=timestamp_submit,
                                 exchange_order_id=exchange_order_id,
                                 group_id=group_id,
                                 fill=FillCollector(price_orig=price_orig, qty_orig=qty_orig),
                                 timestamp=timestamp,
                                 maker=maker,
                                 working=working)
